package view
{
	/**
	 *
	 *@author CrazyChen 
	 *2013-4-8
	 */	
	import data.Globals;
	
	import flash.display.Bitmap;
	import flash.events.Event;
	import flash.geom.Point;
	
	import manager.MapConfig;
	
	import utils.LoaderManage;
	
	import view.base.ClearView;
	import view.other.ShanghaiWall;
	
	public class BackgroundView extends ClearView
	{
		[Embed(source="resources/map/node.png")]
		private var LineNode:Class;
		
		private var bg:Bitmap;
		
		private var shanghaiWall:ShanghaiWall;
		
		public function BackgroundView()
		{
			super();
			shanghaiWall = new ShanghaiWall();
			this.mouseChildren = false;
			this.mouseEnabled = false;
		}
		
		public function initface():void{
			if(bg){
				this.addChild(bg);
				initNode();
			}else{
				LoaderManage.getInstance().loaderContent(Globals.RES_URL + "map/background.jpg",complete);
			}
		}
		
		/**
		 * 初始化城墙
		 */
		private function initWall():void
		{
			this.addChild(shanghaiWall);
			shanghaiWall.refreshView();
		}
		
		private function complete(event:Event):void
		{
			bg = event.target.content;
			bg.height = 480;
			this.addChild(bg);
			initNode();
		}
		
		private function initNode():void{
			var i:int=0;
			var point:Point;
			var line:Array = MapConfig.getInstance().line;
			for(i;i<line.length;i++){
				point = line[i];
				var bmp:Bitmap = new LineNode();
				this.addChild(bmp);
				bmp.x = point.x - Globals.GRAD_WIDTH/2;
				bmp.y = point.y - Globals.GRAD_HEIGHT/2;
			}
			
			initWall();
		}
		
	}
}